package com.ysd.servlet.admin;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ysd.dao.impl.GuanLiYuanimpl;
import com.ysd.entity.GuanLiYuan;
import com.ysd.util.BaseServlet;
import com.ysd.util.Result;

public class AdminGuanLiYuanServlet extends BaseServlet {
	
	 
	/**
	 * localhost:8080/meizizi/adminGuanLiYuan?reqName=login
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setCharacterEncoding("UTF-8");
		PrintWriter out=response.getWriter();
		String username=request.getParameter("username");
		String password=request.getParameter("password");
		GuanLiYuanimpl aDao=new GuanLiYuanimpl();
		GuanLiYuan guanliyuan=aDao.getGuanLiYuanUsername(username);
		if (guanliyuan==null) {
			out.print(Result.toClient(false, "", "账号错误"));
		}else {
			if(guanliyuan.getPassword().equals(password)) {
				HttpSession session=request.getSession();
				session.setAttribute("guanliyuan", guanliyuan);
				out.print(Result.toClient(true, guanliyuan, "登陆成功"));
			}else {
				out.print(Result.toClient(false, "", "密码错误"));
			}
		}
	}

}
